package plus;

import java.util.Arrays;

import plus.run.VM;

public class M_System extends Module {
	public int sysModID;
	private SProc[] sps = new SProc[16];
	int maxSP = -1;
	public void attach(SProc bif) {
		maxSP ++;
		if (maxSP >= sps.length) grow();
		sps[maxSP] = bif;
		bif.home = this;
		bif.id = maxSP;
		fe.enter(bif.sym);
	}

	private void grow() {
		if (sps.length >= 256) throw new RuntimeException("Too many procedures in a system module.");
		sps = Arrays.copyOf(sps, maxSP*2);
	}

	public void callSysProc(int u8) { sps[u8].call(); }

	@Override
	public void compileStartup() {
		// Nothing to do.
	}

	@Override
	public void install() { VM.attach(this); }

}
